package xm.erzhan.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import xm.erzhan.models.ResourceEntity;


public interface ResourceRepository extends JpaRepository<ResourceEntity, Integer> {

    @Modifying
    @Transactional
    @Query("update ResourceEntity resource set resource.name=:qName, " + "resource.resourceMap=:qResourceMap, " +
            "resource.productPowerMap=:qProductPowerMap, resource.population=:qPopulation, " +
            "resource.populationSurplus=:qPopulationSurplus, resource.officer=:qOfficer, " +
            "resource.army=:qArmy, " + "resource.buildingsMap=:qBuildingsMap, " +
            "resource.indorsationCount=:qIndorsationCount, resource.complaintCount=:qComplaintCount, " +
            "resource.tax=:qTax, resource.cityDefense=:qCityDefense, resource.localY=:qLocalY, " +
            "resource.localX=:qLocalX, resource.resourceBuildingsMap=:qResourceBuildingsMap," +
            "resource.lastUpdateTime=:qLastUpdateTime where resource.id=:qId")
    public void updateUser(@Param("qName") String name,
                           @Param("qResourceMap") String resourceMap,
                           @Param("qProductPowerMap") String productPowerMap,
                           @Param("qPopulation") int population,
                           @Param("qPopulationSurplus") int populationSurplus,
                           @Param("qOfficer") String officer,
                           @Param("qArmy") String army,
                           @Param("qBuildingsMap") String buildingsMap,
                           @Param("qIndorsationCount") int indorsationCount,
                           @Param("qComplaintCount") int complaintCount,
                           @Param("qTax") int tax,
                           @Param("qCityDefense") String cityDefense,
                           @Param("qLocalY") double localY,
                           @Param("qLocalX") double localX,
                           @Param("qResourceBuildingsMap") String resourceBuildingsMap,
                           @Param("qLastUpdateTime") Long lastUpdateTime

    );

    public ResourceEntity findByPlayerId(@Param("qPlayerId") int playerId);


}
